package com.yc.mybatis.mapper;

import com.yc.mybatis.entity.Goods;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/10/26
 * Email haijunzhou@hnit.edu.cn
 */
public interface GoodsMapper {

    @Select("<script>" +
            "select * from goods\n" +
            "        <where>\n" +
            "            <if test=\"id != null\">\n" +
            "                and id = #{id}\n" +
            "            </if>\n" +
            "            <if test=\"name != null\">\n" +
            "                and name = #{name}\n" +
            "            </if>\n" +
            "            <if test=\"nums != null\">\n" +
            "                and nums >= #{nums}\n" +
            "            </if>\n" +
            "            <if test=\"bigNum != null\">\n" +
            "                and nums &lt;= #{bigNum}\n" +
            "            </if>\n" +
            "        </where>" +
            "</script>")
    List<Goods> select(GoodsEx goods);

    @Update("<script>" +
            "update goods\n" +
            "        <set>\n" +
            "            <if test=\"name != null\">\n" +
            "                name=#{name},\n" +
            "            </if>\n" +
            "            <if test=\"type != null\">\n" +
            "                type=#{type},\n" +
            "            </if>\n" +
            "            <if test=\"nums != null\">\n" +
            "                nums=#{nums},\n" +
            "            </if>\n" +
            "            <if test=\"price != null\">\n" +
            "                price=#{price},\n" +
            "            </if>\n" +
            "            <if test=\"state != null\">\n" +
            "                state=#{state},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id=#{id}" +
            "</script>")
    void update(Goods goods);

    @Update("update goods set name=#{name}, name=#{type}," +
            " name=#{nums}, name=#{price}, name=#{state}" +
            " where id = #{id}")
    void updateAll(Goods goods);

    @Select("select * from goods where id = #{id}")
    Goods selectById(int id);

    List<Goods> selectByName(@Param("name") String name,
                             @Param("op") int op);

    List<Goods> selectByIds(@Param("ids") List<Integer> ids);

    List<Goods> selectByType(@Param("type") String type,
                             @Param("role") String role,
                             @Param("buy") Boolean buy,
                             @Param("sort") String sort);
    List<Map<String,Object>> selectSql(@Param("sql")String sql);
}


